﻿using Smobiler.Core;
using Smobiler.Core.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;

namespace FubiManger.UI
{
    partial class StaffForm : Smobiler.Core.Controls.MobileForm
    {
        public StaffForm() : base()
        {
            //This call is required by the SmobilerForm.
            InitializeComponent();
        }
        private string type = "";
        /// <summary>
        /// 商户ID
        /// </summary>
        public string merchantid { get; set; }
        private void panclose_Press(object sender, EventArgs e)
        {
            this.Close();
        }
        /// <summary>
        /// 选择时
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void poptype_Selected(object sender, EventArgs e)
        {
            btntype.Text = poptype.Selection.Text;
            type= poptype.Selection.Value;
        }

        private void btnsub_Press(object sender, EventArgs e)
        {
            if (txtphone.Text.Length != 11)
            {
                MessageBox.Show("手机号格式不正确");
            }
            else if (string.IsNullOrEmpty(txtname.Text))
            {
                MessageBox.Show("请填写员工姓名");
            }
            else if (btntype.Text == "岗位")
            {
                MessageBox.Show("请设置岗位");
            }
            else
            {
                if (adminsDal.Querybyphone(txtphone.Text, merchantid) > 0)
                {
                    MessageBox.Show("该手机已经是员工");
                }
                else
                {
                    string pwd = AesUtil.EncryptString("123456");
                    if (adminsDal.Addnewadmin(txtphone.Text, pwd, merchantid, txtname.Text, type) > 0)
                    {
                        Toast("员工添加成功");
                        txtname.Text = "";
                        txtphone.Text = "";
                        btntype.Text = "岗位";
                        type = "";
                    }
                }
                  
            }
        }

        private void btntype_Press(object sender, EventArgs e)
        {
            poptype.ShowDialog();
        }
    }
}